﻿
namespace NetROS.Tiers.Windows.Forms
{
	/// <summary>
	/// abstract RadniNalogVeza typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class RadniNalogVezaDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<RadniNalogVezaDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.RadniNalogVeza _currentRadniNalogVeza = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxRadniNalogVezaDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxRadniNalogVezaErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxRadniNalogVezaBindingSource;
		
		/// <summary> 
		/// the DGV column associated with the IDParent property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxIDParentDataGridViewColumn;
		/// <summary> 
		/// the DGV column associated with the IDChild property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxIDChildDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
				
		private Entities.TList<Entities.Dokument> _IDChildList;
		
		/// <summary> 
		/// The list of selectable Dokument
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.Dokument> IDChildList
		{
			get {return this._IDChildList;}
			set 
			{
				this._IDChildList = value;
				this.uxIDChildDataGridViewColumn.DataSource = null;
				this.uxIDChildDataGridViewColumn.DataSource = this._IDChildList;
			}
		}
		
		private bool _allowNewItemInIDChildList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of Dokument
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInIDChildList
		{
			get { return _allowNewItemInIDChildList;}
			set
			{
				this._allowNewItemInIDChildList = value;
				this.uxIDChildDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
				
		private Entities.TList<Entities.Dokument> _IDParentList;
		
		/// <summary> 
		/// The list of selectable Dokument
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.Dokument> IDParentList
		{
			get {return this._IDParentList;}
			set 
			{
				this._IDParentList = value;
				this.uxIDParentDataGridViewColumn.DataSource = null;
				this.uxIDParentDataGridViewColumn.DataSource = this._IDParentList;
			}
		}
		
		private bool _allowNewItemInIDParentList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of Dokument
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInIDParentList
		{
			get { return _allowNewItemInIDParentList;}
			set
			{
				this._allowNewItemInIDParentList = value;
				this.uxIDParentDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.RadniNalogVeza> _RadniNalogVezaList;
				
		/// <summary> 
		/// The list of RadniNalogVeza to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.RadniNalogVeza> RadniNalogVezaList
		{
			get {return this._RadniNalogVezaList;}
			set
			{
				this._RadniNalogVezaList = value;
				this.uxRadniNalogVezaBindingSource.DataSource = null;
				this.uxRadniNalogVezaBindingSource.DataSource = value;
				this.uxRadniNalogVezaDataGridView.DataSource = null;
				this.uxRadniNalogVezaDataGridView.DataSource = this.uxRadniNalogVezaBindingSource;				
				//this.uxRadniNalogVezaBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxRadniNalogVezaBindingSource_ListChanged);
				this.uxRadniNalogVezaBindingSource.CurrentItemChanged += new System.EventHandler(OnRadniNalogVezaBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnRadniNalogVezaBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentRadniNalogVeza = uxRadniNalogVezaBindingSource.Current as Entities.RadniNalogVeza;
			
			if (_currentRadniNalogVeza != null)
			{
				_currentRadniNalogVeza.Validate();
			}
			//_RadniNalogVeza.Validate();
			OnCurrentEntityChanged();
		}

		//void uxRadniNalogVezaBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.RadniNalogVeza"/> instance.
		/// </summary>
		public Entities.RadniNalogVeza SelectedRadniNalogVeza
		{
			get {return this._currentRadniNalogVeza;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxRadniNalogVezaDataGridView.VirtualMode;}
			set
			{
				this.uxRadniNalogVezaDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxRadniNalogVezaDataGridView.AllowUserToAddRows;}
			set {this.uxRadniNalogVezaDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxRadniNalogVezaDataGridView.AllowUserToDeleteRows;}
			set {this.uxRadniNalogVezaDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxRadniNalogVezaDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxRadniNalogVezaDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="RadniNalogVezaDataGridViewBase"/> class.
		/// </summary>
		public RadniNalogVezaDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxRadniNalogVezaDataGridView = new System.Windows.Forms.DataGridView();
			this.uxRadniNalogVezaBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxRadniNalogVezaErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIDParentDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			this.uxIDChildDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			//this.uxIDChildBindingSource = new DokumentBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDChildBindingSource)).BeginInit();
			//this.uxIDParentBindingSource = new DokumentBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDParentBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxRadniNalogVezaDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxRadniNalogVezaBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxRadniNalogVezaErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxRadniNalogVezaErrorProvider
			// 
			this.uxRadniNalogVezaErrorProvider.ContainerControl = this;
			this.uxRadniNalogVezaErrorProvider.DataSource = this.uxRadniNalogVezaBindingSource;						
			// 
			// uxRadniNalogVezaDataGridView
			// 
			this.uxRadniNalogVezaDataGridView.AutoGenerateColumns = false;
			this.uxRadniNalogVezaDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxRadniNalogVezaDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIDParentDataGridViewColumn,
		this.uxIDChildDataGridViewColumn			});
			this.uxRadniNalogVezaDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxRadniNalogVezaDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxRadniNalogVezaDataGridView.Name = "uxRadniNalogVezaDataGridView";
			this.uxRadniNalogVezaDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxRadniNalogVezaDataGridView.TabIndex = 0;	
			this.uxRadniNalogVezaDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxRadniNalogVezaDataGridView.EnableHeadersVisualStyles = false;
			this.uxRadniNalogVezaDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnRadniNalogVezaDataGridViewDataError);
			this.uxRadniNalogVezaDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnRadniNalogVezaDataGridViewCellValueNeeded);
			this.uxRadniNalogVezaDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnRadniNalogVezaDataGridViewCellValuePushed);
			
			//
			// uxIDParentDataGridViewColumn
			//
			this.uxIDParentDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDParentDataGridViewColumn.DataPropertyName = "IDParent";
			this.uxIDParentDataGridViewColumn.HeaderText = "IDParent";
			this.uxIDParentDataGridViewColumn.Name = "uxIDParentDataGridViewColumn";
			this.uxIDParentDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDParentDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDParentDataGridViewColumn.ReadOnly = false;		
			//
			// uxIDChildDataGridViewColumn
			//
			this.uxIDChildDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDChildDataGridViewColumn.DataPropertyName = "IDChild";
			this.uxIDChildDataGridViewColumn.HeaderText = "IDChild";
			this.uxIDChildDataGridViewColumn.Name = "uxIDChildDataGridViewColumn";
			this.uxIDChildDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDChildDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDChildDataGridViewColumn.ReadOnly = false;		
			//
			// uxIDChildDataGridViewColumn
			//				
			this.uxIDChildDataGridViewColumn.DisplayMember = "IDDokumentTip";	
			this.uxIDChildDataGridViewColumn.ValueMember = "ID";	
			this.uxIDChildDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxIDChildDataGridViewColumn.DataSource = uxIDChildBindingSource;				
				
			//
			// uxIDParentDataGridViewColumn
			//				
			this.uxIDParentDataGridViewColumn.DisplayMember = "IDDokumentTip";	
			this.uxIDParentDataGridViewColumn.ValueMember = "ID";	
			this.uxIDParentDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxIDParentDataGridViewColumn.DataSource = uxIDParentBindingSource;				
				
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxRadniNalogVezaDataGridView);
			this.Name = "RadniNalogVezaDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDChildBindingSource)).EndInit();
			//((System.ComponentModel.ISupportInitialize)(this.uxIDParentBindingSource)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxRadniNalogVezaErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxRadniNalogVezaDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxRadniNalogVezaBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				RadniNalogVezaDataGridViewEventArgs args = new RadniNalogVezaDataGridViewEventArgs();
				args.RadniNalogVeza = _currentRadniNalogVeza;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class RadniNalogVezaDataGridViewEventArgs : System.EventArgs
		{
			private Entities.RadniNalogVeza	_RadniNalogVeza;
	
			/// <summary>
			/// the  Entities.RadniNalogVeza instance.
			/// </summary>
			public Entities.RadniNalogVeza RadniNalogVeza
			{
				get { return _RadniNalogVeza; }
				set { _RadniNalogVeza = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxRadniNalogVezaDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnRadniNalogVezaDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxRadniNalogVezaDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnRadniNalogVezaDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxRadniNalogVezaDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDParentDataGridViewColumn":
						e.Value = RadniNalogVezaList[e.RowIndex].IDParent;
						break;
					case "uxIDChildDataGridViewColumn":
						e.Value = RadniNalogVezaList[e.RowIndex].IDChild;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxRadniNalogVezaDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnRadniNalogVezaDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxRadniNalogVezaDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDParentDataGridViewColumn":
						RadniNalogVezaList[e.RowIndex].IDParent = (System.Int32)e.Value;
						break;
					case "uxIDChildDataGridViewColumn":
						RadniNalogVezaList[e.RowIndex].IDChild = (System.Int32)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
